<!DOCTYPE html>
<html>
<head>
<title>req_new</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />

<link rel="stylesheet" type="text/css"
	href="/codebase/fonts/font_roboto/roboto.css" />
<link rel="stylesheet" type="text/css" href="/codebase/dhtmlx.css" />
<script type="text/javascript" src="/codebase/dhtmlx.js"></script>
<style>
div#simpleLog {
	height: 200px;
	font-family: Roboto, Arial, Helvetica;
	font-size: 14px;
	color: #404040;
	overflow: auto;
}
</style>
<script>
/*<![CDATA[*/
Date.prototype.Format = function (fmt) { //author: meizz 
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "h+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

	var myForm, logObj,att_group,atts,attObj;
	var customCss = {
		video_bitrate : "validate_magenta",
		video_codec : "validate_orange"
	};
	function doOnLoad() {
		//alert("onload");
		if (myForm) {
			myForm.unload();
			myForm = null;

		}
		
	
		
		myForm = new dhtmlXForm("form_container");
		myForm.loadStruct("/common/testmanager/req_new.xml",function(){
			
		
			var myDate =new Date().Format("yyyy-MM-dd");
			myForm.setItemValue("accept_date",myDate); 
			
		});

		myForm.attachEvent("onButtonClick", function(name) {
			
			if (name = "req_submit") {
				//doFormValidate();
				 if(confirm("你确定要提交？"))					 
				    {
					 this.send("req/req_new_save",callback);				 
				     }
				
			}
		});
		
		myForm.attachEvent("onChange", function (name, value){
		     if(name == "req_type"){
		    	 if(value == "缺陷转需求"){
		    		 myForm.setRequired("deffect_no",true);		    		 
		    	 }else{
		    		 myForm.setRequired("deffect_no",false);		    		
		    	 }
		     }
		     if(name=="accept_date"){
			    	var current_Date = new Date();
			    	if(value>current_Date){
			    		alert("【接收日期】需要小于或等于当前日期,请更正");	
			    		
			    	}	    	
			    	
			 }
		     
		});
		
		myForm.attachEvent("onValidateError", function (name, value, result){
			var tmp_label=myForm.getItemLabel(name);	
		
		    alert("校验【"+tmp_label+"】 值为【"+value+ "】 ， 请更正");
		   
		    
		});
		
		myForm.attachEvent("onUploadFile", function(realName, serverName) {
			atts_add_gropid(arguments[2].att_gropid);
			atts_add_ids(arguments[2].att_ids);
			//var mu=myForm.getUploader("myFiles");
		});
		
		myForm.attachEvent("onUploadComplete",function(count){
			//logEvent("<br></br>onUploadComplete "+count+" file"+(count>1?"s were":" was")+" uploaded");
			alert("上传"+count+"个文件完成.");
		});
		
		myForm.attachEvent("onUploadFail",function(realName){
			//logEvent("onUploadFail, file: "+realName);
			alert("上传文件"+realName+"失败，请检查上传文件大小");
		});
		
		function logEvent(t) {
			if (!logObj)
				logObj = document.getElementById("simpleLog");
			logObj.innerHTML += t + "";
		}
		
		function atts_add_ids(ids) {
			var txt="";
			//var get_input_att_ids=myForm.getInput("att_id");
			//txt=get_input_att_ids.value;
			txt=myForm.getItemValue("att_id");
			if (txt==""){
				//get_input_att_ids.value=ids;
				myForm.setItemValue("att_id",ids);
			}else{
				//get_input_att_group.value=txt+","+ids;
				myForm.setItemValue("att_id",txt+","+ids);
			}				
			//att_group.hide=true;
			//atts.hidden=true;
		}
		
		function atts_add_gropid(g_id) {
			var txt="";
			//var get_input_att_group=myForm.getInput("att_group_id");
			//txt=get_input_att_group.value;
			txt=myForm.getItemValue("att_group_id");
			if (txt==""){
				//get_input_att_group.value=g_id;
				myForm.setItemValue("att_group_id",g_id);
			}else{
				//get_input_att_group.value=txt+","+g_id;
				myForm.setItemValue("att_group_id",txt+","+g_id);
			}				
			//att_group.hidden=true;
			//atts.hide=true;
		}
		
		//	req_type_Select=new dhtmlXSelect("req_type");

		//	myForm.attachEvent("onValidateSuccess", doCustomCss);
		//	myForm.attachEvent("onValidateError", doCustomCss);
	}

	function logEvent(t, name, command) {
		if (!logObj)
			logObj = document.getElementById("simpleLog");
		logObj.innerHTML += t;
	}
	function clearLog() {
		if (!logObj)
			logObj = document.getElementById("simpleLog");
		logObj.innerHTML = "";
	}

	function doFormValidate() {
		myForm.validate();
	}
	var callback=function () {
		//alert("callback");
		
		if(arguments[1]=="true"){
			alert("保存需求成功");	
			doOnLoad();
// 			myForm.clear();
// 			var myUploader = myForm.getUploader("myFiles");
// 			myUploader.clear();
		}
		else{
			alert("保存需求失败，错误信息："+arguments[1]);
		}
	}

/*]]>*/
	
</script>
</head>
<body onload="doOnLoad();">
	<table>
		<tr>
			<td>
				<div id="form_container" 
					style="padding-left: 50px;"></div>
			</td>
		</tr>		
		
	</table>
</body>
</html>